package com.example.pei.ithinklearnt.view.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.pei.ithinklearnt.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import static com.example.pei.ithinklearnt.utils.ImageLoaderUtil.displayImage;
import static com.example.pei.ithinklearnt.utils.ImageLoaderUtil.getPhotoImageOption;


/**
 * 这是一个启动页广告活动 这应当是启动活动
 */
public class AdvertisingActivity extends Activity {

    private int waitTime=3;
    private TextView tvTime;

    private final static int SHOW_RESPONSE=1;
    private Handler handler=new Handler(){
        public void handleMessage(Message msg){
            switch (msg.what){
                case SHOW_RESPONSE:
                    Intent intent=new Intent(AdvertisingActivity.this,Login_Activity.class);
                    startActivity(intent);
                    finish();
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_advertising);

        ImageView ivAdvertising = findViewById(R.id.iv_advertising);
        tvTime=findViewById(R.id.tv_s);
        String url="http://bmob-cdn-6346.b0.upaiyun.com/2018/03/19/93d24606ce1c4b42b228e219581e492e.jpg";
      //  displayImage(this,ivAdvertising,url, getPhotoImageOption());

        sendRequest();
    }
    private void sendRequest() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while(waitTime>0) {

                    try {
                        Thread.sleep(0);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    changeTime();
                    waitTime--;
                }
                Intent intent = new Intent(AdvertisingActivity.this, Login_Activity.class);
                startActivity(intent);
                finish();
                //Message message = new Message();
               // message.what = SHOW_RESPONSE;
               // handler.sendMessage(message);
            }
        }).start();
    }
    private void changeTime(){
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tvTime.setText(waitTime+"...");
            }
        });
    }
}
